<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- <h1>我是www下的index</h1> -->
    <form action="">
        <input type="user" placeholder="用户名" name="">
        <input type="password" placeholder="密码" name="">
        <input type="submit" value="注册">

    </form>

    <script>
        var inps = document.querySelectorAll('input');
        document.forms[0].onsubmit = function (e) {
            e.preventDefault();
            // 发送ajax请求

            var xhr = new XMLHttpRequest();
            xhr.open('post', '/zhuce');
            xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')


            var u = inps[0].value;
            var p = inps[1].value;
            xhr.send(`username=${u}&password=${p}`);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    console.log(xhr.responseText);
                    var res = JSON.parse(xhr.responseText);
                    console.log(res);

                }
            }

        }
    </script>
</body>

</html>